package ch.quantasy.android.remoteZapper;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class RemoteZapperMessageBroadcastReceiver extends BroadcastReceiver {
	private static final String TAG = "ZAP";
	public static final String REMOTE_ZAPPER_MESSAGE_RECEIVED = "ch.quantasy.android.remoteZapper.RemoteZapperMessageBroadcastReceiver.MESSAGE_RECEIVED_ACTION";
	public static final String MESSAGE = "message";

	public static Intent getRemoteZapperMessageIntent(final String message) {
		final Intent intent = new Intent(
				RemoteZapperMessageBroadcastReceiver.REMOTE_ZAPPER_MESSAGE_RECEIVED);
		intent.putExtra(RemoteZapperMessageBroadcastReceiver.MESSAGE, message);
		return intent;
	}

	@Override
	public void onReceive(final Context context, final Intent intent) {
		Log.d(RemoteZapperMessageBroadcastReceiver.TAG, "Intent received: "
				+ intent);
		if (intent != null) {
			final String message = intent
					.getStringExtra(RemoteZapperMessageBroadcastReceiver.MESSAGE);
			final Intent zapperIntent = RemoteZapperService
					.getZapperIntent(message);
			Log.d(RemoteZapperMessageBroadcastReceiver.TAG,
					"Sending intent to service");
			context.startService(zapperIntent);
			Log.d(RemoteZapperMessageBroadcastReceiver.TAG,
					"Intent sent to service");
		}
	}

}
